def p(a):
    alf=["zero","one","two","three","four","five","six","seven","eight","nine"]
    for i in range(10):
        if a==alf[i]:
            return i
    return -1
def is_prime(a):
    for i in range(2, int(a**0.5)+1):
        if a%i==0:
            return False
    return True
def main(a1,a2,a3):
    b1=p(a1)
    if (b1==-1):
        print("Wrong input")
        return 0
    b2=p(a2)
    if (b2==-1):
        print("Wrong input")
        return 0
    b3=p(a3)
    if (b3==-1):
        print("Wrong input")
        return 0
    b=b1*100+b2*10+b3
    i=0
    while True:
        if (is_prime(b-i)):
            print(b-i)
            return 0
        if (is_prime(b+i)):
            print(b+i)
            return 0
        i+=1
    return 0
a1,a2,a3=input().split()
main(a1,a2,a3)